﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace WXYW.BLL
{
    public static class DateTimeService
    {
        public static int CalculateDateTimeSpan(DateTime startDateTime, DateTime endDateTime)
        {
            if (endDateTime > startDateTime)
            {
                int timeSpan = (endDateTime - startDateTime).Days;

                int holiday = 0;
                for (DateTime date = startDateTime; date < endDateTime; date = date.AddDays(1))
                {
                    if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                    {
                        holiday++;
                    }
                }

                timeSpan -= holiday;
                return timeSpan;
            }
            else if (endDateTime.Year == startDateTime.Year && endDateTime.Month == startDateTime.Month &&
                endDateTime.Day == startDateTime.Day)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
